package com.example.thegreatwall.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.example.thegreatwall.common.R;
import com.example.thegreatwall.entity.Inventory;
import com.example.thegreatwall.service.InventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequestMapping("/inventory")
@CrossOrigin(origins = "*") //无论什么源都可以访问  不写这个不允许跨域
@RestController
public class InventoryController {
    @Autowired
    private InventoryService inventoryService;
    @GetMapping(value = "getInventory")
    public R getInventory(@RequestParam int product_id,@RequestParam int product_type,@RequestParam String record_date) {
        QueryWrapper<Inventory> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("product_id",product_id);
        queryWrapper.eq("product_type",product_type);
        queryWrapper.like("record_date",record_date);
        return new R().addDate("list",inventoryService.getOne(queryWrapper));
    }

    //确认支付   -- 然后写修改状态 1
    @GetMapping(value = "confirmDeduction")
    public boolean confirmDeduction(@RequestParam int productId,@RequestParam int productType,@RequestParam String recordDate,@RequestParam int quantity) {
        boolean b = inventoryService.confirmDeduction(productId, productType, recordDate, quantity);
        return b;
    }
        //取消时调用  -- 然后写修改状态 2
    @GetMapping(value = "releaseLockedInventory")
    public boolean releaseLockedInventory(@RequestParam int productId,@RequestParam int productType,@RequestParam String recordDate,@RequestParam int quantity){
        boolean b = inventoryService.releaseLockedInventory(productId, productType, recordDate, quantity);
        return b;
    }
}
